package cn.csc.module.member.controller.app.weixin;

import cn.binarywang.wx.miniapp.api.WxMaService;
import cn.binarywang.wx.miniapp.config.WxMaConfig;
import cn.csc.framework.common.pojo.CommonResult;
import cn.csc.module.system.api.social.SocialClientApi;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import me.chanjar.weixin.common.error.WxErrorException;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

import static cn.csc.framework.common.pojo.CommonResult.success;

/**
 * @author liuchuang
 * @version 1.0
 * @modify
 * @since 2025/4/21 11:27
 */
@Tag(name = "微信小程序")
@RestController
@RequestMapping("/member/wx-ma")
@Validated
@Slf4j
public class AppWxMaController {

    // 使用本服务配置文件生成
    @Resource
    private WxMaService maService;

    @Resource
    private SocialClientApi socialClientApi;

    @PostMapping("/create-qrcode-bytes")
    @Operation(summary = "创建微信二维码",
            description = "参考 https://developers.weixin.qq.com/miniprogram/dev/OpenApiDoc/qrcode-link/qr-code/getUnlimitedQRCode.html 文档")
    public CommonResult<byte[]> createQrcodeBytes(@RequestParam("path") String path) throws WxErrorException {
        WxMaConfig wxMaConfig = maService.getWxMaConfig();
        log.info("微信小程序配置： {}, appId:{}", wxMaConfig, wxMaConfig.getAppid());
        byte[] qrcodeBytes = maService.getQrcodeService().createQrcodeBytes(path, 420);
        return success(qrcodeBytes);
    }



}
